package megrez.oss.local.domain;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;
import megrez.oss.local.utils.MetadataNotFoundException;

/**
 * 元数据服务
 *  
 * @author Lucky Yang
 * @since 2.6.9
 */
@Service
@RequiredArgsConstructor
public class MetadataService {
    private final MetadataRepository metadataRepo;


    @Transactional(rollbackFor = Exception.class)
    public Metadata update(String id, String name) {      
        Metadata metadata = this.findById(id);
        metadata.setName(name);
        return metadataRepo.save(metadata);
    }

    public Metadata findById(String id) {
        return metadataRepo.findById(id).orElseThrow(() -> new MetadataNotFoundException(id));
    }     
}
